﻿using System;
using Amarok.Agents;


namespace Amarok.Samples
{
	/// <summary>
	/// </summary>
	public static class EntryPoint
	{
		/// <summary>
		/// </summary>
		public static void Main()
		{
			// instantiate and run our extended runtime. this runtime will initialize the message bus 
			// and provide the environment for hosting and running agents, which will be loaded through
			// subsystems.

			using (var runtime = new MyRuntime())
			{
				// start the runtime. this will load subsystems, which again might load other subsystems 
				// and/or spawn agents. agents spawned from subsystems are automatically connected to the
				// runtime's message bus.
				runtime.Start();

				// trace messages on the message bus
				runtime.Environment.MessageBus.Subscribe<Message>(msg =>
					{
						Console.WriteLine("-> " + msg);
					});

				Console.WriteLine("Press any key to start...");
				Console.ReadKey();

				// publish a very specific message onto the message bus that will activate previously spawned 
				// agents. this is the start signal for all your application's agents to start processing.
				runtime.Publish(new ApplicationStarted());

				Console.WriteLine("Press any key to exit...");
				Console.ReadKey();
			}

			// disposing the runtime will tear down all subsystems and agents previously spawned, but only those
			// agents and subsystems that have be loaded or spawned from subsystems or from the runtime. agents
			// spawned via AgentFactory are not automatically disposed. it is also a good idea to tear down your
			// application via specific messages much like ApplicationStarted instead of forcibly disposing all 
			// agents, because that will give your application's agents time to shut down, store data, save 
			// settings, etc.
		}

	}
}
